var enumUtils = {};
enumUtils.deviceStatus = {
  locked: { key: 1, name: '锁定' },
  activate: { key: 2, name: '激活' },
  close: { key: 3, name: '封闭' },
  open: { key: 4, name: '开放' },
  list: {},
  get: function (tkey) {
    return get(enumUtils.deviceStatus, tkey);
  },
};
function list(typeList) {
  // console.log("typeList",typeList);
  var arr = [];
  for (var key in typeList) {
    if (key != 'list' && key != 'get' && key != 'getObj') {
      arr.push(typeList[key]);
    }
  }
  return arr;
}

function get(typeObj, key, dvalue) {
  var name = dvalue || '-';
  for (var tkey in typeObj) {
    var obj = typeObj[tkey];
    if (key == obj.key) {
      name = obj.name;
    }
  }
  return name;
}

function getObj(typeObj, key) {
  // 跟据key值获取枚举对象
  var obj = {};
  for (var tkey in typeObj) {
    const tempobj = typeObj[tkey];
    if (key == tempobj.key) {
      obj = tempobj;
      obj.skey = tkey;
    }
  }
  return obj;
}

for (var funkey in enumUtils) {
  var typeObj = enumUtils[funkey];
  for (var key in typeObj) {
    if (key == 'list') {
      typeObj[key] = list(typeObj);
    }
  }
}

// 获取对象的key值
function getKey(typeObj) {
  const resArr = [];
  Object.keys(typeObj).forEach((v) => {
    if (v != 'list' && v != 'get' && v != 'getObj' && v != 'keys') {
      resArr.push(v);
    }
  });
  return resArr;
}
export default {
  install(Vue, options) {
    Vue.prototype.enumUtils = enumUtils;
  },
};
